package com.aaa.controller.back;

import com.aaa.entity.Position;
import com.aaa.service.back.PositionService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RequestMapping("/position")
@Controller
public class PositionController {

    @Resource
    private PositionService positionService;

    @RequestMapping("/findPosition")
    public String findPosition(Model model){
        List<Map<String, Object>> positionList = positionService.findPosition();
        model.addAttribute("positionList",positionList);
        return "back/position-list";
    }

    @RequestMapping("/addPositionShow")
    public String addPositionShow(){
        return "back/position-add";
    }

    @RequestMapping("/addPositionSubmit")
    public String addPositionSubmit(Position position){
        positionService.addPosition(position);
        return "redirect:/position/findPosition";
    }

    @RequestMapping("/editPositionShow")
    public String editPositionShow(Integer positionId,Model model){
        Map<String, Object> positionMap = positionService.findByPositionId(positionId);
        model.addAttribute("positionMap",positionMap);
        return "back/position-edit";
    }

    @RequestMapping("/editPositionSubmit")
    public String editPositionSubmit(Position position){
        positionService.editPosition(position);
        return "redirect:/position/findPosition";
    }
}
